import { useUserStore } from '@/stores/userStore';
import jwt_decode from 'jwt-decode';

export default () => {
  let jwt =
    localStorage.getItem('auth_token') ||
    'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXNzd29yZCI6IiQyYSQxMCQzUEM2MWNWQkRYcENsTmJuQlZsL3B1MUhXY0VqdzhXaEVsWjIvT2RpVklNSHh6UERXWmRWVyIsInBlcm1pc3Npb25zIjoiYWRtaW4iLCJuYW1lIjoi5byg5LiJIiwiZGVwYXJ0bWVudCI6IuWFrOWuieWxgCIsInVzZXJuYW1lIjoiMTI0In0.zzu14f9WVHibTOSEY5lBTopO0u1eDOrerN9hbGRoF2A';
  if (jwt) {
    let token: any = null;
    token = jwt_decode(jwt);
    !!token && useUserStore().setUser(token);
  }
};
